import uvicorn
from fastapi import FastAPI
from langserve import add_routes

from langChain.config import model

chain_1 = model

# 5. 创建LangServe应用
app = FastAPI(title="聊天机器人", version="1.0")

# 添加路由 (支持流式)
add_routes(
    app,
    chain_1,
    path="/chat",
    enable_feedback_endpoint=True,
    enabled_endpoints=("invoke", "batch", "stream", "config_hashes"),
)

if __name__ == "__main__":
    # 启动服务 (访问 http://localhost:8000/chat/playground)
    uvicorn.run(app, host="0.0.0.0", port=8000)
